#!/usr/bin/env python
# encoding=utf-8
import re
import sys

import utils

reload(sys)
sys.setdefaultencoding("utf-8")


def run():
    url = 'http://support.clean-mx.de/clean-mx/xmlviruses?format=xml&response=alive&fields=ip'
    content = utils.get_url_content(url)

    ips = []
    for index, ip in enumerate(re.findall(ur'\d+\.\d+\.\d+\.\d+', content)):
        ips.append({
            '_id': ip,
            "sourceUrl": "http://support.clean-mx.de/clean-mx/xmlviruses?format=xml&response=alive&fields=ip",
            "sourceName": "Clean MXMalwarePublic",
            "detail": "",
            "cause": ""
        })
    utils.save2db(ips)
    # for x in ips:
    #     print x

if __name__ == '__main__':
    run()